#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<sys/types.h>
#include <vector>
using namespace std;

class Task
{
  public:
  Task(int x,int y)
  {
    _x=x;
  _y=y;
  }
   ~Task()
  {
    
  }
  int Excute()
  {
    return _x+_y;
  }
  private:
  int _x;
  int _y;
};


class threaddata
{
  public:
  threaddata(int x,int y,string threadname):_threadname(threadname),_t(x,y)
  {

  }
   ~threaddata()
  {

  }
  string getthreadname()
  {
    return _threadname;
  }
  int run()
  {
    return _t.Excute();
  }
  private:
  string _threadname;
  Task _t;
};

class Result
{
  public:
  Result()
  {

  }
  ~Result()
  {
    
  }
  void Print()
  {
    cout<<_threadname<<" : " <<_result<<endl;
  }
void Setresult(int result,string&threadname)
{
_result=result;
_threadname=threadname;
}
private:
int _result;
string _threadname;
};
void*threadrun(void*args)
{
   threaddata* td=(threaddata*)args;
    string name=td->getthreadname();
   Result*res=new Result;
   int result=td->run();
   res->Setresult(result,name);
   delete td;
   sleep(2);
   return res;
}

int main()
{
  vector<pthread_t>threads;

  for(int i=0;i<5;i++)
  {
      char name[64];
    snprintf(name,64,"thread-%d",i+1);
    threaddata*td=new threaddata(10,20,name);
    pthread_t tid;
    pthread_create(&tid,nullptr,threadrun,td);
    threads.push_back(tid);
  }
  vector<Result*>result_set;
  void*ret=nullptr;
    for(auto&tid:threads)
    {
        pthread_join(tid,&ret);
        result_set.push_back((Result*)ret);
    }
    for(auto&res:result_set)
    {
      res->Print();
      delete res;
    }
    return 0;
}